<?php

namespace App\Observers;

use App\Handlers\KeysHandler;
use App\Models\User;
use Illuminate\Support\Facades\Cache;

class UserObserver
{

    public function saved(User $user)
    {
        $key_id = sprintf(KeysHandler::USER_INFO, 'id', $user->id);
        $key_tiktokid = sprintf(KeysHandler::USER_INFO, 'tiktokid', $user->tiktokid);
        Cache::forget($key_id);
        Cache::forget($key_tiktokid);
    }

    public function deleted(User $user)
    {
        $key_id = sprintf(KeysHandler::USER_INFO, 'id', $user->id);
        $key_tiktokid = sprintf(KeysHandler::USER_INFO, 'tiktokid', $user->tiktokid);
        Cache::forget($key_id);
        Cache::forget($key_tiktokid);
    }
}
